package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.dto.PojoDto;
import com.example.entity.vo.Business.InvmabVoListDto;
import com.example.entity.vo.InvmaHeadVo;
import com.example.entity.vo.InvmabVo;
import com.example.entity.yifei.Invmb;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LiangPandeng
 * @since 2024-02-26
 */
public interface InvmbMapper extends BaseMapper<Invmb> {

    List<InvmabVo> selectInvmabVoList(@Param("dto") InvmabVoListDto dto);

    List<InvmaHeadVo> selectInvmaHeadVoList();

    IPage<Invmb> selectInvmbList(Page<Invmb> page);

    List<InvmaHeadVo> selectInvmaHeadVoTreeList();

    List<String> getInvmbByMA002(String ma002);


//    List<String> yourQuery(String keyword);

    @DS("demo")
    @Select("SELECT MB029 FROM INVMB WHERE MB001 = #{TE007}")
    String getMB029(String TE007);

    @DS("demo")
    List<Invmb> query(PojoDto pojoDto);

    @DS("demo")
    Invmb querys(String ph);

    @DS("erp3_help")
    @Select("SELECT * FROM INVMB")
    List<Invmb> all();

    @Select("SELECT MB001 FROM INVMB")
    List<String> mb001List();

    @Select("SELECT \n" +
            "    CASE \n" +
            "        WHEN EXISTS (SELECT 1 FROM MOCTA WHERE TA006 = #{mb001}) OR \n" +
            "             EXISTS (SELECT 1 FROM MOCTB WHERE TB003 = #{mb001}) OR \n" +
            "             EXISTS (SELECT 1 FROM inspectionHead WHERE TA006 = #{mb001}) \n" +
            "        THEN 1 \n" +
            "        ELSE 0 \n" +
            "    END AS Exists_Check;")
    Integer havingLinkTable(String mb001);
}
